﻿using FrameWork.Core.Cryption;
using FrameWork.Core.Enum;
using FrameWork.Core.Utils;
using FrameWork.Services;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace AncheStart.Converter
{
    public class ChannelStateToChineseConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Type type=  typeof(EnumChannelState);
    
   
            if (GlobalConstant.EnumChannelStateFieldInfoDescriptionAttributes == null)
            {
                value = value.ObjToInt();
                GlobalConstant.EnumChannelStateFieldInfoDescriptionAttributes = Utils.GetFieldInfoDescriptionAttributes(type);

            }

            string propName = type.GetEnumName(value);

            string? statusValue = GlobalConstant.EnumChannelStateFieldInfoDescriptionAttributes.FirstOrDefault(s=>s.Name==propName)?.DescriptionAttribute?.Description;

            if (!string.IsNullOrEmpty(statusValue))
            {
                return statusValue;
            }
            return "未定义";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
